<?php
namespace app\index\controller\product;
use app\admin\model\GoodsClassification;
class ProductClass extends \app\index\controller\BaseIndex{
    public function index(\think\Request $request){
        //接收分类条件
        $category = $request->get('category');
        //接收口味条件
        $taste = $request->get('taste');
        //实例化商品分类表
        $gc = new GoodsClassification();
        //关联预载入
        $gc = $gc->hasWhere('goods',['is_delete'=>0])->with('goods');
        //根据商品的类别进行商品查询
        //预制商品类别条件
        $categoryCondition = [
            '1' => '1',
            '2' => '2',
            '3' => '3',
            '4' => '4',
            '5' => '5',
            '6' => '6',
        ];
        if(array_key_exists($category, $categoryCondition) === true){
            $gc = $gc->where('category',$category);
        }
        //根据商品的口味进行商品查询
        //预制商品口味条件
        $tasteCondition = [
            '1' => '1',
            '2' => '2',
            '3' => '3',
            '4' => '4',
            '5' => '5',
            '6' => '6',
            '7' => '7',
            '8' => '8',
            '9' => '9',
        ];
        if(array_key_exists($taste, $tasteCondition) === true){
            $gc = $gc->where('taste',$taste);
        }        
        $goods = $gc->limit(36)->select();
        $data = [];
        $data['goods'] = $goods;
        return view('product/productClass',$data);
    }
}